<!--
- Author:   .
- Date:    2017/7/4 0004.
- File:    my.
-->
<template>
  <div>
    <div class="Web_Box">
      <div class="my_tis disn"><a href=""><i class="iconfont icon-tishi"></i><span>您的个人资料还未完善，请完善个人资料</span><i class="iconfont icon-rightdot2"></i></a></div>
      <!--新顶部-->
      <div class="newmy_head newtext">
        <a href="javascript:">
          <!--<i class="iconfont icon-rightdot"></i>-->
          <div style="top:32px;" class="newmy_head_portrait"><img src="../assets/images/photo.png" alt=""></div>
          <div style="margin-top: 30px;" class="newmy_head_name">
            <span>{{memberInfo.member_truename}}</span>
            <br><br>
            <b>
              <i class="iconfont icon-zichan2"></i>
              {{memberInfo.level==1?"会员":memberInfo.level==2?"店长":memberInfo.level==3?"明星店长":memberInfo.level==4?"股东":"普通用户"}}
            </b>
          </div>
          <p class="">{{memberInfo.member_mobile}}&nbsp;|&nbsp;邀请码：{{memberInfo.member_id}}
            <span @click="copy" v-show="false && $deviceType == 'APICloud'">复制</span>
          </p>
        </a>
      </div>
      <!--收益/提现-->
      <div class="newmy_Profit">
        <div class="newmy_Profit_btn">
          <span ><router-link :to="{name: 'integral-income', query: {type: '2'}}">来源明细</router-link></span>
          <span ><router-link :to="{name: 'integral-history', query: {type: '2'}}">转出记录</router-link></span>
          <span @click="gotoTrade()"><a style="width: 80%;height: 30px;line-height: 30px;font-size: 14px;color: #fff;background: #e67a7e;border-radius: 5px;display: inline-block;">转给个人</a></span>
        </div>
      </div>
      <!--收益明细-->
      <div class="newmy_pcount">

        <ul>
          <li style="width: 25%;">
            <a href="javascript:">
              <span>云宝</span>
              <em>{{memberInfo.freeze_balance}}</em>
            </a>
          </li>
          <li style="width: 25%;">
            <a href="javascript:">
              <span>云通证</span>
              <em>{{memberInfo.hg_balance}}</em>
            </a>
          </li>
          <li style="width: 25%;">
            <a href="javascript:">
              <span>云积分</span>
              <em>{{memberInfo.hf_balance}}</em>
            </a>
          </li>
          <li style="width: 25%;">
            <a href="javascript:">
              <span>云券</span>
              <em>{{memberInfo.hq_balance}}</em>
            </a>
          </li>
        </ul>
      </div>
      <!--<div class="MyHeadnew">-->

        <!--<div class="Photo"><img src="../assets/images/photo.png" alt=""/></div>-->
        <!--<div class="newtext">-->
          <!--<h1 class="slh">{{memberInfo.member_truename}}(<span v-show="memberInfo.level==1">会员</span><span v-show="memberInfo.level==2">店长</span><span v-show="memberInfo.level==3">明星店长</span><span v-show="memberInfo.level==4">股东</span>)<a class="Bindaccount" v-show="memberInfo.is_vip == 1">已激活</a></h1>-->
          <!--<p class="">{{memberInfo.member_mobile}}&nbsp;|&nbsp;邀请码：{{memberInfo.member_id}}-->
            <!--<span @click="copy" v-show="false && $deviceType == 'APICloud'">复制</span></p>-->
        <!--</div>-->

      <!--</div>-->
      <!--<div class="balance">-->
        <!--<ul class="f-cb">-->
          <!--<li><span>{{memberInfo.freeze_balance}}</span><p>云宝</p></li>-->
          <!--<li><span>{{memberInfo.hg_balance}}</span><p>花股</p></li>-->
          <!--<li><span>{{memberInfo.hf_balance}}</span><p>云积分</p></li>-->
          <!--&lt;!&ndash;<li><span>{{memberInfo.hf_balance}}</span><p>花劵</p></li>&ndash;&gt;-->
        <!--</ul>-->
      <!--</div>-->

      <!--<div class="newbtnbox">-->
        <!--<ul class="f-cb">-->
          <!--<li><div class="newbtn"><router-link :to="{name: 'integral-income', query: {type: '2'}}">来源明细</router-link></div></li>-->
          <!--<li><div class="newbtn2"><router-link :to="{name: 'integral-history', query: {type: '2'}}">转出记录</router-link></div></li>-->
          <!--<li><div class="newbtn3"><router-link :to="{name: 'account-tranfer', query: {type: '2'}}">转给个人</router-link></div></li>-->
        <!--</ul>-->

      <!--</div>-->
      <!--<div class="newbanlance">-->
        <!--<ul class="f-cb">-->
          <!--<li @click="gotoOrderList"><i class="iconfont icon-dingdanguanl"></i>我的订单</li>-->
          <!--<li><i class="iconfont icon-zhifu1"></i>支付金额<span style="margin-left: 15px;color: #f83166;margin-top: 4px">{{memberInfo.order_amount}}</span></li>-->
          <!--<li @click="gotoTransfer"><i class="iconfont icon-iconfontjiaoyi"></i>云宝交易区</li>-->
          <!--<li @click="gotoTeam"><i class="iconfont icon-tuandui"></i>我的团队</li>-->
          <!--<li @click="gotoSpread"><i class="iconfont icon-erweima1"></i>推广二维码</li>-->
          <!--<li @click="gotoNextSum"><i class="iconfont icon-yuyan"></i>查看</li>-->
          <!--<li><a href="tel:4000053114"><i class="iconfont icon-dianhua" style="text-overflow: ellipsis;overflow: hidden;white-space: nowrap;"></i><span>客服:</span><span style="color: #54b331;">4000053114</span></a></li>-->
          <!--<li v-show="memberInfo.member_id != '11155'" @click="gotoDownHelp"><i class="iconfont icon-caozuo"></i>操作流程</li>-->
          <!--<li v-show="memberInfo.member_id != '11155'" @click="gotoNewsList"><i class="iconfont icon-xiaoxi1"></i>资讯</li>-->
          <!--<li @click="gotoMemberInfo"><i class="iconfont icon-zichan"></i>注册日志查询</li>-->
          <!--<li @click="gotoSetName"><i class="iconfont icon-edit"></i>修改名字</li>-->
          <!--<li @click="gotoSetting"><i class="iconfont icon-shezhi"></i>设置</li>-->
        <!--</ul>-->
      <!--</div>-->
      <div class="newmy_mid_item">
        <ul>
          <li @click="gotoOrderList">
            <a href="javascript:void(0)"><em><img src="../assets/images/chunqiu/dingd.png"></em>
              <span>我的订单</span>
            </a>
          </li>
          <li>
            <a href="javascript:void(0)"><em><img src="../assets/images/chunqiu/qianb.png"></em>
              <span>支付金额</span>
              <span style="position: absolute;left: 0;bottom: 45px;margin: 0;line-height: 12px;color: rgb(248, 49, 102);font-size: 10px;">({{memberInfo.order_amount}})</span>
            </a>
          </li>
          <li @click="gotoTransfer">
            <a href="javascript:void(0)"><em><img src="../assets/images/chunqiu/jiaoy.png"></em>
              <span>云宝交易区</span>
            </a>
          </li>
          <li @click="gotoTeam">
            <a href="javascript:void(0)"> <em><img src="../assets/images/chunqiu/tuand.png"></em>
              <span>我的团队</span>
            </a>
          </li>
          <li @click="gotoSpread">
            <a href="javascript:void(0)"><em><img src="../assets/images/chunqiu/erwm.png"></em>
              <span>推广二维码</span>
            </a>
          </li>
          <li @click="gotoNextSum">
            <a href="javascript:void(0)"> <em><img src="../assets/images/chunqiu/chak.png"></em>
              <span>查看</span>
            </a>
          </li>
          <li @click="gotoMemberInfo">
            <a href="javascript:void(0)"> <em><img src="../assets/images/chunqiu/shouycx.png"></em>
              <span>收益查询</span>
            </a>
          </li>
          <li v-show="memberInfo.member_id != '11155'" @click="gotoDownHelp">
            <a href="javascript:void(0)"> <em><img src="../assets/images/chunqiu/liuc.png"></em>
              <span>操作流程</span>
            </a>
          </li>
          <li v-show="memberInfo.member_id != '11155'" @click="gotoNewsList">
            <a href="javascript:void(0)"> <em><img src="../assets/images/chunqiu/zix.png"></em>
              <span>咨讯</span>
            </a>
          </li>
          <!--<li @click="gotoMemberInfo">-->
            <!--<a href="javascript:void(0)"> <em><img src="../assets/images/chunqiu/dingd.png"></em>-->
              <!--<span>注册日志</span>-->
            <!--</a>-->
          <!--</li> -->
          <li>
            <a href="tel:4000053114"><em><img src="../assets/images/chunqiu/kef.png"></em>
              <span>客服</span>
              <span style="position: absolute;left: 0;bottom: 40px;margin: 0;line-height: 12px;color: rgb(84, 179, 49);font-size: 10px;">4000053114<br>(转2号键)</span>
            </a>
          </li>
          <li>
          <a href="javascript:void(0)"> <em><img src="../assets/images/chunqiu/xiug.png"></em>
            <span>客服微信</span>
            <span style="position: absolute;left: 0;bottom: 45px;margin: 0;line-height: 12px;color: rgb(84, 179, 49);font-size: 10px;">cwz13114</span>
          </a>
        </li>
          <li @click="gotoSetting">
            <a href="javascript:void(0)"> <em><img src="../assets/images/chunqiu/shez.png"></em>
              <span>设置</span>
            </a>
          </li>
        </ul>
      </div>
      <div @click="signOut" class=" newmy_kuozhan" style="margin-top:8px;">
        <a href="javascript:void(0)">退出登录</a>
      </div>
    </div>

    <footer-tab></footer-tab>
  </div>
</template>

<script>
  import * as request from '../request'
  import payPop from '../components/payPop'
  import HotNews from '../components/hot-news.vue'

  export default {
    beforeRouteEnter(to, from, next) {
      request.getMemberInfo().then(data => {
        // if (data.is_active == '1') {
        //   next(vm => {
        //     vm.memberInfo = data
        //   })
        // } else {
        //   next({name: 'member-tobeVip'})
        // }
        next(vm => {
          vm.memberInfo = data
        })
      }).catch(e => {
        next()
      })
    },
    data() {
      return {
        noticeList: [],
        memberInfo: {},
        memberNoticeList: {requested: false, allLoaded: false, data: [], page: '1', pageSize: '10'},
        countList: {requested: false, data: {}},
        memberAllow: {data: [1212, 13138, 13140, 11222, 11223, 11232, 11215, 11216, 14088, 13198, 10547, 13810]}
      }
    },
    components: {
      'hotNews': HotNews
    },
    created() {
      this.getNoticeList()
      this.$request.getAdvList()
      this.getCountList()
    },
    computed: {
      payedMoney: function () {
        let payedMoney = 0
        if (this.memberInfo.sub_fee == '0.00' || this.memberInfo.is_refund_2 == '1') {
          payedMoney = parseFloat(this.memberInfo.handle_fee) + parseFloat(this.memberInfo.bj_sub_fee)
          if (this.memberInfo.is_refund_1 == '1') {
            payedMoney = payedMoney - this.memberInfo.handle_fee
          }
          if (this.memberInfo.is_refund_3 == '1') {
            payedMoney = payedMoney - this.memberInfo.bj_sub_fee
          }
        } else {
          payedMoney = this.memberInfo.sub_fee
        }
        return payedMoney
      },
      ifNewMemberNotice: function () {
        let ifNew = false
        for (let i = 0; i < this.memberNoticeList.data.length; i++) {
          if (this.memberNoticeList.data[i].is_read == '0') {
            ifNew = true
            break
          }
        }
        return ifNew
      }
    },
    methods: {
      gotoTrade() {
        if (!this.checkUserStatus()) {
          return
        }
        this.$router.push({name: 'account-tranfer'})
      },
      withdraw() {
        // this.$messageBox.confirm('提现需扣除千分之二手续费哦！转经验值则全额到账，您确定提现吗？').then(() => {
        this.$router.push({name: 'account-withdraw', query: {type: '2'}})
        // }).catch(e => {
        // })
      },
      checkUserStatus() {
        if (this.memberInfo.member_state == '0' || this.memberInfo.is_refund_1 == '1' || this.memberInfo.is_refund_2 == '1' || this.memberInfo.is_refund_3 == '1') {
          this.$messageBox.alert('您的账户已冻结').then(data => {
          })
          return false
        }
        if (this.memberInfo.is_vip != '1') {
          this.$messageBox.alert('请购买任一商品激活账户', '未激活').then(data => {
          })
          return false
        }
        return true
      },
      gotoTransfer() {
        for (let i = 0; i < this.memberAllow.data.length; i++) {
          console.log(this.memberAllow.data[i])
          if (this.memberInfo.member_id == this.memberAllow.data[i]) {
            if (!this.checkUserStatus()) {
              return
            }
            this.$router.push({name: 'transfer-transaction'})
            break
          } else {
            this.$messageBox.alert('版本更新中').then(data => {
            })
          }
        }
        // if (!this.checkUserStatus()) {
        //   return
        // }
        // this.$router.push({name: 'transfer-transaction'})
      },
      gotoNextSum() {
        if (!this.checkUserStatus()) {
          return
        }
        this.$router.push({name: 'member-nextSum'})
      },
      gotoSetName() {
        if (!this.checkUserStatus()) {
          return
        }
        this.$router.push({name: 'setting-name'})
      },
      gotoBankcardList() {
        if (!this.checkUserStatus()) {
          return
        }
        this.$router.push({name: 'bankcard-list'})
      },
      gotoSetting() {
        this.$router.push({name: 'setting-index'})
      },
      gotoMemberInfo() {
        if (!this.checkUserStatus()) {
          return
        }
        this.$router.push({name: 'account-reward'})
      },
      gotoNewsList() {
        if (!this.checkUserStatus()) {
          return
        }
        this.$router.push({name: 'news-list', params: {id: '12'}})
      },
      gotoSpread() {
        if (!this.checkUserStatus()) {
          return
        }
        this.$router.push({name: 'setting-about'})
      },
      gotoTeam() {
        if (!this.checkUserStatus()) {
          return
        }
        this.$router.push({name: 'member-friend'})
      },
      gotoOrderList() {
        if (!this.checkUserStatus()) {
          return
        }
        this.$router.push({name: 'order-list'})
      },
      getNoticeList() {
        this.$request.getNoticeList().then(data => {
          this.noticeList = data
        })
      },
      gotoIdentify() {
        if (!this.checkUserStatus()) {
          return
        }
        if (this.memberInfo.is_verify_idcard == '0' || this.memberInfo.is_verify_idcard == '3') {
          this.$router.push({name: 'member-identifyAdd'})
        }
        if (this.memberInfo.is_verify_idcard == '1' || this.memberInfo.is_verify_idcard == '2') {
          this.$router.push({name: 'member-identifyInfo'})
        }
      },
      async pay(goodsId) {
        this.$indicator.open('处理中...')
        let cartId = await this.$request.addGoodsToCart(goodsId, 1) // 加入购物车
        let param = {
          cart_id: [cartId],
          ifcart: 1,
          is_balance: 0,
          is_integral: 0,
          order_note: '',
          pay_name: 'online',
          self: '0',
          is_needship: 0
        }
        let order = await this.$request.submitOrder(param) // 生成订单
        this.$indicator.close()
        payPop({paySn: order.pay_sn, orderId: order.order_id}, this.canclePay)
      },
      getMemberNoticeList() {
        this.memberNoticeList.loading = true
        this.$request.getMemberNoticeList(this.memberNoticeList.page, this.memberNoticeList.pageSize).then(data => {
          if (data.length < this.memberNoticeList.pageSize) {
            this.memberNoticeList.allLoaded = true
          }
          this.memberNoticeList.data = [...this.memberNoticeList.data, ...data]
        }).finally(() => {
          this.memberNoticeList.loading = false
          this.memberNoticeList.requested = true
        })
      },
      gotoDownHelp() {
        if (!this.checkUserStatus()) {
          return
        }
        this.$router.push({name: 'news-detail', params: {id: '11'}}) // 后台11是操作流程说明的文章的id
//        this.$router.push({name: 'iframe', query: {title: '操作流程', url: 'http://v.baihuae.com/weixin/plat/app/Html/41/418648/Detail_29.php?single_id=8305&C_id=41&fromuser=oLPnuwF5cSTdjxRqxz3ff3jiVn6M&wxref=mp.weixin.qq.com'}})
      },
      copy() { // 需要添加pasteboard或clipBoard模块才能调用系统剪切板
      },
      gotoMemberDetail() {
        this.$router.push({name: 'setting-index'})
      },
      gotoGzh() {
        if (this.$deviceType != 'APICloud') {
          this.$router.push({name: 'setting-gzh'})
        } else {
          this.$router.push({name: 'setting-gzh-help'})
        }
      },
      gotoFwh() {
        this.$router.push({name: 'setting-fwh'})
      },
      gotoAccountIndex() {
        this.$router.push({name: 'account-index'})
      },
      gotoMemberNoticeList() {
        this.$router.push({name: 'member-notice-list'})
      },
      gotoOrderListByType(type) {
        this.$router.push({name: 'order-list', query: {type: type}})
      },
      gotoRefundList() {
        this.$router.push({name: 'refund-list', query: {type: this.$dictionary.refundType.money}})
      },
      getCountList() {
        this.$request.getCountList().then(data => {
          this.countList.data = data
        }).finally(() => {
          this.countList.requested = true
        })
      },
      signOut() {
        this.$storage.delKey()
        this.$storage.setAuthed(false)
        this.$storage.delMemberInfo()
        this.$utils.delCookie('key')
        this.$router.replace({name: 'home'})
      }
    }
  }
</script>

<style>

</style>
